package com.zzt.book.config;

import com.zzt.book.model.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * Created with IntelliJ IDEA.
 * Description
 * User: panda
 * Date: 2025-03-29
 * Time: 15:51
 */
@Slf4j
@ControllerAdvice
@ResponseBody
//@RestControllerAdvice
public class ExceptionAdvice {

//    @ExceptionHandler
//    public Result handler(Exception e){
//        log.error("发生异常：e: ", e);
//        return Result.fail("内部错误， 请联系管理员");
//    }
//
//    @ExceptionHandler
//    public Result handler(NullPointerException e){
//        log.error("发生异常：e: ", e);
//        return Result.fail("空指针异常错误， 请联系管理员");
//    }
//
//    @ExceptionHandler
//    public Result handler(IndexOutOfBoundsException e){
//        log.error("发生异常：e: ", e);
//        return Result.fail("数组越界异常错误， 请联系管理员");
//    }

    @ExceptionHandler(Exception.class)
    public Result handler(Exception e){
        log.error("发生异常：e: ", e);
        return Result.fail("内部错误， 请联系管理员");
    }

    @ExceptionHandler(NullPointerException.class)
    public Result handler2(Exception e){
        log.error("发生异常：e: ", e);
        return Result.fail("空指针异常错误， 请联系管理员");
    }

    @ExceptionHandler(IndexOutOfBoundsException.class)
    public Result handler3(Exception e){
        log.error("发生异常：e: ", e);
        return Result.fail("数组越界异常错误， 请联系管理员");
    }

}
